package com.site.wisdom_construction.controller.statisticsModule;

import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.service.personnelModule.ContractWorkersStatisticsService;
import com.site.wisdom_construction.service.personnelModule.ManagerialStaffStatisticsService;
import com.site.wisdom_construction.service.statisticsModule.StatisticsPersonService;
import com.site.wisdom_construction.statisticsResult.CountPersonByHt;
import com.site.wisdom_construction.statisticsResult.ListCount;
import com.site.wisdom_construction.statisticsResult.PersonAllCount;
import com.site.wisdom_construction.util.verification.NoToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/24
 * @Description
 */
@Api(tags = "人员模块统计数据接口")
@RestController
@RequestMapping("StatisticsPerson")
@CrossOrigin
public class StatisticsPersonController {
    @Autowired
    private StatisticsPersonService statisticsPersonService;

    @Autowired
    private ContractWorkersStatisticsService contractWorkersStatisticsService;

    @Autowired
    private ManagerialStaffStatisticsService managerialStaffStatisticsService;

    @ApiOperation(value = "人员模块首页头部数据", notes = "测试数据:")
    @PostMapping("/CountPersonByHt")
    @NoToken
    public OneDataResult CountPersonByHt(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        CountPersonByHt countPersonByHt = new CountPersonByHt();
        //劳务队总数
        countPersonByHt.setLabourAmount(statisticsPersonService.countLabourEnterpriseByStatus(map));
        //劳务人员总数
        countPersonByHt.setWorkerAmountAll(statisticsPersonService.countWorkerAll(map));
        //在场人员总数
        countPersonByHt.setWorkerAmount(statisticsPersonService.countWorkerBySceneStatus(map));
        //未培训人数
        countPersonByHt.setWorkerNoTrainAmount(statisticsPersonService.countWorkerAll(map) - statisticsPersonService.countWorkerByTrainStatus(map));
        Double all = Double.valueOf(statisticsPersonService.countWorkerAll(map));
        Double px = Double.valueOf(statisticsPersonService.countWorkerByTrainStatus(map));
        Double d = (px/all) * 100;
        String workerTrain = String.valueOf(d);
        //培训率
        if("NaN".equals(workerTrain) || "0.0".equals(workerTrain)){
            countPersonByHt.setWorkerTrain("0");
        }else if ("100.0".equals(workerTrain)){
            countPersonByHt.setWorkerTrain("100");
        }else {
            if (workerTrain.length() == 3){
                countPersonByHt.setWorkerTrain(workerTrain.substring(0,3));
            }else if (workerTrain.length() == 4){
                countPersonByHt.setWorkerTrain(workerTrain.substring(0,4));
            }else {
                countPersonByHt.setWorkerTrain(workerTrain.substring(0,5));
            }
        }


        oneDataResult.setData(countPersonByHt);
        return oneDataResult;
    }

    @ApiOperation(value = "按照年龄段统计劳务人员数据", notes = "测试数据:")
    @PostMapping("/countByAgeBracket")
    @NoToken
    public OneDataResult countByAgeBracket(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(statisticsPersonService.countByAgeBracket(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据劳务队统计劳务人员数据", notes = "测试数据:")
    @PostMapping("/countBySubcontractorsName")
    @NoToken
    public OneDataResult countBySubcontractorsName(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(statisticsPersonService.countBySubcontractorsName(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据工种统计劳务人员数据", notes = "测试数据:")
    @PostMapping("/countByProfessionName")
    @NoToken
    public OneDataResult countByProfessionName(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(statisticsPersonService.countByProfessionName(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据区域统计劳务人员数据", notes = "测试数据:")
    @PostMapping("/countByWorkerProvince")
    @NoToken
    public OneDataResult countByWorkerProvince(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(statisticsPersonService.countByWorkerProvince(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据性别统计劳务人员数据", notes = "测试数据:")
    @PostMapping("/countByWorkerSex")
    @NoToken
    public OneDataResult countByWorkerSex(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(statisticsPersonService.countByWorkerSex(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据名族统计劳务人员数据", notes = "测试数据:")
    @PostMapping("/countByWorkerNation")
    @NoToken
    public OneDataResult countByWorkerNation(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(statisticsPersonService.countByWorkerNation(map));
        return oneDataResult;
    }

    @ApiOperation(value = "劳务人员月在职情况分析", notes = "测试数据:")
    @PostMapping("/selectContractWorkersStatistics")
    @NoToken
    public OneDataResult selectContractWorkersStatistics(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(contractWorkersStatisticsService.selectContractWorkersStatistics(map));
        return oneDataResult;
    }

    @ApiOperation(value = "管理人员月在职情况分析", notes = "测试数据:")
    @PostMapping("/selectManagerialStaffStatistics")
    @NoToken
    public OneDataResult selectManagerialStaffStatistics(@RequestBody Map map) {
        System.out.println("map："+map);
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(managerialStaffStatisticsService.selectManagerialStaffStatistics(map));
        return oneDataResult;
    }

    @ApiOperation(value = "管理人员月在职情况分析", notes = "测试数据:")
    @RequestMapping("/selectManagerialStaffStatisticsString")
    @NoToken
    public OneDataResult selectManagerialStaffStatisticsString(@RequestBody Map map) {
        System.out.println("map："+map);
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(managerialStaffStatisticsService.selectManagerialStaffStatistics(map));
        return oneDataResult;
    }

    @ApiOperation(value = "人员类型统计" , notes = "测试数据:")
    @PostMapping("/countSafetyDangerStatisticsNew")
    public OneDataResult countRiskShowNew(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        List<PersonAllCount> personAllCountList = new LinkedList<>();

        //安管人员
        PersonAllCount personAllCountA = new PersonAllCount();
        personAllCountA.setTypeName("安管人员");
        personAllCountA.setAmount(statisticsPersonService.countManagerialStaffStatus(map));
        personAllCountList.add(personAllCountA);

        //劳务人员
        PersonAllCount personAllCountB = new PersonAllCount();
        personAllCountB.setTypeName("劳务人员");
        personAllCountB.setAmount(statisticsPersonService.countWorkerBySceneStatus(map));
        personAllCountList.add(personAllCountB);
        oneDataResult.setData(personAllCountList);
        return oneDataResult;
    }

    @ApiOperation(value = "人员总数" , notes = "测试数据:")
    @PostMapping("/countPersonStatisticsAll")
    public OneDataResult countPersonStatisticsAll(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(statisticsPersonService.countManagerialStaffStatus(map)+statisticsPersonService.countWorkerBySceneStatus(map));
        return oneDataResult;
    }
}
